package com.team.app.util;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

public class BeanUtil {
	public static void copy(Object fromBean,Object toBean){		
		try{
			BeanInfo beanInfo = Introspector.getBeanInfo(fromBean.getClass());
			PropertyDescriptor[] pdList = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pdList) {
				Method writeMethod = pd.getWriteMethod();
				Method readMethod = pd.getReadMethod();
				if (readMethod == null || writeMethod == null) {
					continue;
				}
				Object val = readMethod.invoke(fromBean);
				if(val != null)
				writeMethod.invoke(toBean, val);
			
			}
		}catch(Exception e){}
	}
	
}
